$(function() {
	$('#vue_vm_list').hide();
});

function mealsCostRecord_findByMonth() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	var year = $('#year').val();
	var month = $('#month').val();
	
	find_basic_by_json(path+'/mealsCostRecord/findByMonth', {month: getStandardMonth(year, month)}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getMealsCostRecordTotal:function(todos) {
					var totalMoney = 0;
					for(var i=0; i<todos.length; i++) {
						for(var j=0; j<todos[i].baseMealsCostRecordForms.length; j++) {
							var payMoney = todos[i].baseMealsCostRecordForms[j].payMoney;
							var quantity = todos[i].baseMealsCostRecordForms[j].quantity;
							totalMoney += parseFloat((payMoney*quantity).toFixed(2)); //parseFloat必不可少，不然，js会把toFixed的结果当作字符串处理。
						}
					}
					
					return totalMoney;
				}
			}
		});
		
		$('#vue_vm_list').show();
	});
}

function mealsCostRecord_findByDay() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	var year = $('#year').val();
	var month = $('#month').val();
	var day = $('#day').val();
	
	find_basic_by_json(path+'/mealsCostRecord/findByDay', {month: getStandardDay(year, month, day)}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list').show();
	});
}

function mealsCostRecord_findPersonMealsCostRecord() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	var startYear = $('#startYear').val();
	var startMonth = $('#startMonth').val();
	var startDay = $('#startDay').val();
	var endYear = $('#endYear').val();
	var endMonth = $('#endMonth').val();
	var endDay = $('#endDay').val();
	var searchVal = $('#searchVal').val();
	var startTime = getStandardDay(startYear, startMonth, startDay);
	var endTime = getStandardDay(endYear, endMonth, endDay);
	
	find_basic_by_json(path+'/mealsCostRecord/findPersonMealsCostRecord',
		{startDay: startTime, endDay: endTime, searchVal: searchVal}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list').show();
	});
}